<?php 

Class ModuleResultOfPlanSubscription extends CmsCustomModule {

    private function setHeadString($condition=null,$sort_by=null,$rand_code) {
        $date_list = null;
        $current_time = date('Y-m-d H:i:s');
        $gender_list = ' NONE ';
        $age_group_list = ' NONE ';
        $region_country_list = ' NONE ';
        $subscription_plan = 'NONE';
        $category_list = ' NONE ';
        
        if (!empty($condition) && is_array($condition)) {

            //date time.
            if (isset($condition['play_time']['start_date']) && isset($condition['play_time']['end_date'])) {
                $date_list = '<strong>By Date: </strong>&nbsp; <b>From</b> '.$condition['play_time']['start_date'].' <b>To</b> '.$condition['play_time']['end_date'];
            }
            else {
                $date_list = '<b>By Month: </b>&nbsp;'.$condition['play_time']['start_month'].' <b>To</b> '.$condition['play_time']['end_month'];
            }
            
            //gender & age.
            if (!empty($condition['gender'])) {
                $gender_list = (count($condition['gender'])==0) ? 'NONE' : ((count($condition['gender'])==2) ? 'ALL' : (($condition['gender'][0]=='M') ? 'Male' : 'Female'));
            }

            $age_group_mapping = AC::getInstance()->getConfigSetting(AC::$age_list);
            if (!empty($condition['age_group'])) {
                $tmp_age_mapping = array();
                foreach($age_group_mapping as $k=>$v) {
                    if ($k<=0) continue;
                    $tmp_age_mapping[] = $k;
                }

                foreach($condition['age_group'] as $key=>$val) {
                    $tmp_ages[]= $age_group_mapping[$val];
                }
                $age_group_list = (count($tmp_age_mapping)==count($tmp_ages)) ? 'ALL' : implode(', ',$tmp_ages);                
            }
            
            //region & country
            if (!empty($condition['country_code'])) {
                $country_arr = $condition['country_code'];
                $region_country_list = AC::getInstance()->getCountryListToHeader($country_arr);
            }
            
            //subscription plan
            if (!empty($condition['package'])) {
                $plan_array = AC::getInstance()->getConfigSetting(AC::$video_plan_package);
                $tmp_plan = array();
                foreach($plan_array as $key=>$val) {
                    if ($key==0 && strtoupper($val)=='ALL') continue;
                    $tmp_plan[] = $key;
                }

                $tmp_plan_list = array();
                foreach($condition['package'] as $key=>$val) {
                    $tmp_plan_list[] = $plan_array[$val];
                }

                $subscription_plan = (count($tmp_plan)==count($tmp_plan_list)) ? 'ALL' : implode(', ',$tmp_plan_list);
            }
        }

        $condition_list = '<br/>'.
                          '<div>'.$date_list.'</div>'.
                          '<div><b>Subscription Plan: </b>&nbsp;'.$subscription_plan.'</div>'.
			              '<div><b>Gender: </b>&nbsp;'.$gender_list.'</div>'.
			              '<div><b>Age Group: </b>&nbsp;'.$age_group_list.'</div>'.
			              '<table class="nob">'.
                          '<tr>'.
                          ' <td valign="top" width="110">'.
                          '     <b class="tit">Region/Country: </b>&nbsp;</td>'.
                          ' <td valign="top">'.$region_country_list.'</td>'.
                          '</tr>'.
                          '</table>';
        //control tag.                         
        $export_tag =  'Export to '.AC::exportHtmlControl($rand_code,AC::EXPORT_FILE_PREFIX_NAME_PLAN)
                                   .AC::exportPdfControl($rand_code,AC::EXPORT_FILE_PREFIX_NAME_PLAN)
                                   .AC::exportCvsControl($rand_code,AC::EXPORT_FILE_PREFIX_NAME_PLAN);

        //output view string.
        $head_string = '<div class="hd">'.
                       '    <div class="utility">'.
                       '        <a href="#" class="print">Print</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$export_tag.
                       '    </div>'.
                       '    <hr>'.
                       '    <h1>'.$this->title.'</h1>'.
                       '    <div class="ui-helper-clearfix">'.
                       '        <div class="time">'.$current_time.'</div>'.
                       '        <ul>'.$condition_list.'</ul>'.
                       '    </div>'.
                       '</div>';

        //output export string.
        $head_string_exprot = '<div class="hd">'.
                                '    <div class="utility">'.
                                '        <a href="#" class="print">Print</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.
                                '    </div>'.
                                '    <hr>'.
                                '    <h1>'.$this->title.'</h1>'.
                                '    <div class="ui-helper-clearfix">'.
                                '        <div class="time">'.$current_time.'</div>'.
                                '        <ul>'.$condition_list.'</ul>'.
                                '    </div>'.
                                '</div>';

        return array('view'=>$head_string,'export'=>$head_string_exprot);
    }
    
    //get the page search filter condition.
    private function getPageCondition($params) {
        $date = array();
        if (!empty($params['startdate']) && !empty($params['enddate'])) {
            $date['start_date'] = $params['startdate'];
            $date['end_date'] = $params['enddate'];
            if ($params['enddate']<$params['startdate']) $date['end_date'] = date('Y-m-d');
        }

        $month = array();
        if (!empty($params['startmonth']) && !empty($params['endmonth'])) {
            $month['start_month'] = $params['startyear'].'-'.$params['startmonth'];
            $month['end_month'] = $params['endyear'].'-'.$params['endmonth'];
        }
        $play_time = ($params['dateby']=='month') ? $month : $date;


        $age_group = array();
        if (!empty($params['age'])) {
            $tmp_age_group = explode(',',$params['age']);
            foreach($tmp_age_group as $key=>$val) {
                if (intval($val)==-1) {
                    $age_group = array();
                    $tmp_arr = AC::getInstance()->getConfigSetting(AC::$age_list);
                    foreach($tmp_arr as $k=>$v) {
                        if ($k=='0' || $k=='-1') continue;
                        $age_group[] = $k;
                    }
                    break;
                }
                if (intval($val)==0) continue;
                $age_group[] = intval($val);
            }
        }

        $gender = array();
        if (!empty($params['gender'])) {
            $tmp_gender = array('2'=>'M','3'=>'F');
            if ($params['gender']==1) {
                $gender = array('M','F');
            }
            else {
                $gender[] = $tmp_gender[$params['gender']];
            }
        }
        
        $tmp_package = array();
        $tmp_package_key = array();
        $package_arr = (!empty($params['package']) && is_array($params['package'])) ? explode(',',$params['package']) : null ;
        if (!empty($package_arr)) {
            $tmp_package_ = AC::getInstance()->getConfigSetting(AC::$video_plan_package);
            foreach($tmp_package_ as $k=>$v) {
                if ($k==0 && strtoupper($v)=='ALL') continue;
                $tmp_package_key[] = $k;
            }
            foreach($package_arr as $k=>$v) {
                if ($v==0) {
                    $tmp_package = $tmp_package_key;
                    break;
                }
                $tmp_package[] = $v;
            }
        }

        $country = array();
        if (!empty($params['country_code'])) {
            $country = (!empty($params['country_code'])) ? AC::getInstance()->getRegionCountryCondtion(json_decode($params['country_code'],true)) : array();
            
        }

        $dateby = $params['dateby'];
        
        return array('condition'=>array(
                                        'play_time'=>$play_time,
                                        'gender'=>$gender,
                                        'package'=>$tmp_package,
                                        'age_group'=>$age_group,
                                        'country_code'=>$country,
                                        'dateby'=>$dateby));
    }

    //get the table name.
    private function getDateCondition($play_time) {
        $time_list = array();
        $table_name = array();
        $date_condition = '';
        if (!empty($play_time['start_date']) && !empty($play_time['end_date'])) {
            $date_condition .= ' AND (SUBSTRING(order_datetime,1,10)>="'.$play_time['start_date'].'" AND SUBSTRING(order_datetime,1,10)<="'.$play_time['end_date'].'") ';
            $start_ = date('Y',strtotime($play_time['start_date']));
            $end_ = date('Y',strtotime($play_time['end_date']));
            for($i=$start_;$i<=$end_;$i++) {
                $table_name['year'][] = $i;
                $table_name['month'] = 0;
            }
            
            $start_ = strtotime($play_time['start_date']);
            $end_ = strtotime($play_time['end_date']);
            for($i=$start_;$i<=$end_;$i+=86400) {
                $time_list[] = date('Y-m-d',$i);
            }
        }
        elseif(!empty($play_time['start_month']) && !empty($play_time['end_month'])) {
            if ($play_time['start_month']==$play_time['end_month']) {
                $table_name['year'] = date('Y',strtotime($play_time['start_month']));
                $table_name['month'] = date('m',strtotime($play_time['start_month']));
                $date_condition .= ' AND (SUBSTRING(order_datetime,1,7)="'.$table_name['year'].'-'.$table_name['month'].'") ';
                $time_list[] = $table_name['year'].'-'.$table_name['month'];
            }
            else {
                $date_condition .= ' AND (SUBSTRING(order_datetime,1,7)>="'.$play_time['start_month'].'" AND SUBSTRING(order_datetime,1,7)<="'.$play_time['end_month'].'") ';
                $start_ = date('Y',strtotime($play_time['start_month']));
                $start_month_ = date('m',strtotime($play_time['start_month']));

                $end_ = date('Y',strtotime($play_time['end_month']));
                $end_month_ = date('m',strtotime($play_time['end_month']));

                for($i=$start_;$i<=$end_;$i++) {
                    $s_month_ = ($i==$start_) ? intval($start_month_) : 1;
                    $e_month_ = ($i== $end_) ? intval($end_month_) : 12;
                    for($j=$s_month_;$j<=$e_month_;$j++) {
                        $j = ($j<10) ? '0'.$j : $j;
                        $time_list[] = $i.'-'.$j;
                    }
                }
            }
        }

        return array('condition'=>$date_condition,'time_list'=>$time_list);
    }

    //out put the body string.
    private function getOutPutBody($head_string,$body_string) {
        $output ='<div id="result" class="subscription_result" >'.$head_string.
                 '  <div class="bd">'.
                 '      <table border="0" cellpadding="0" cellspacing="0">'.
                 '      <tbody>'.
                 $body_string.
                 '      </tbody>'.
                 '      </table>'.
                 '  </div>'.
                 '</div>';
        return $output;
    }
    
    //define the package arr list.
    static protected function getPackageArr() {
        $package_array = array();
        $package_array_ = AC::getInstance()->getConfigSetting(AC::$video_plan_package);
        foreach($package_array_ as $k=>$v) {
            if ($k<1) continue;
            $package_array[$k] = $v;
        }
        return $package_array;
    }

    //define the age-group arr list.
    static protected function getAgeGroupArr() {
        $age_group_array = array();
        $age_group_array_ = AC::getInstance()->getConfigSetting(AC::$age_list);
        foreach($age_group_array_ as $k=>$v) {
            if ($k<1) continue;
            $age_group_array[$k] = $v;
        }
        return $age_group_array;
    }
    
    //set the body's Title.
    private function setParagraphTitle($title) {
        $body = '<tr>'.
                '   <td colspan="5" class="tit"><div align="center"><strong>'.$title.'</strong></div></td>'.
                '</tr>';
        return $body;
    }
    
    //set the body's sub title.
    private function setSubParagraphTitle($title) {
        $body = '<tr class="weight">'.
                '   <td width="194">Plan:'.$title.'</td>'.
                '   <td width="195">&nbsp;</td>'.
                '   <td width="117">&nbsp;</td>'.
                '   <td width="95">&nbsp;</td>'.
                '   <td width="49">&nbsp;</td>'.
                '</tr>';
        return $body;
    }
    
    //set the body's table header.
    static private function setPlanTableHeader($sub_title) {
        $body = '<tr class="textfield weight" bgcolor="#CCC">'.
				'   <td>'.ucwords($sub_title).'</td>'.
				'   <td class="num">'.AC::SUBSCRIPTION_PLAN_TABLE_HEADER_NEW.'</td>'.
				'   <td class="num">'.AC::SUBSCRIPTION_PLAN_TABLE_HEADER_RENEW.'</td>'.
				'</tr>';
        return $body;
    }
    
    //set the body's table ceils.
    private function setPlanTableBody($data,$date_time_list,$package_id,$aves_list) {
        $body = null;
        if (empty($date_time_list)) return $body;
        $aves_list_flag = (strtoupper($aves_list)=='NONE') ? true : false;

        foreach($date_time_list as $key=>$value) {
            if ($aves_list_flag) {
                $new_num = 0;
                $renew_num = 0;
                if (isset($data[$value][$package_id])) {
                    foreach($data[$value][$package_id] as $k=>$v) {
                        $new_num += (isset($v['new'])) ? $v['new'] : 0;
                        $renew_num += (isset($v['renew'])) ? $v['renew'] : 0;
                    }
                }
            }
            else {
                $new_num = (isset($data[$value][$package_id][$aves_list]['new'])) ? $data[$value][$package_id][$aves_list]['new'] : 0;
                $renew_num = (isset($data[$value][$package_id][$aves_list]['renew'])) ? $data[$value][$package_id][$aves_list]['renew'] : 0;
            }

            $body .= '<tr>'.
                     '   <td class="textfield">'.$value.'</td>'.
                     '   <td class="num">'.number_format($new_num).'</td>'.
                     '   <td class="num">'.number_format($renew_num).'</td>'.
                     '</tr>';
        }
        return $body;
    }

    //set the second line by gender.
    private function setSecondLineWithAvesByGender($data,$package_id,$gender_list,$dateby,$date_time_list,$package_keys) {
        $body = '<tr>'.
		        '   <td colspan="5">'.
                '       <div align="center">';
        foreach($gender_list as $key=>$val) {
            $body .= (strtoupper($val)=='NONE') ? null : '<p><strong>Gender:'.$val.'</strong></p>';
            $body .= '<p>';
            $body .= $this->setSubscriptionPlanLineChart($val,$data,$package_id,$date_time_list,$package_keys);
            $body .= '<table width="100%" border="0">'.self::setPlanTableHeader($dateby).$this->setPlanTableBody($data,$date_time_list,$package_id,$val).'</table>'.
                     '</p>';
        }
        $body .= '      </div>'.
		         '  </td>'.
	             '</tr>'.
                 '<tr><td colspan="5">&nbsp;</td></tr>';
        return $body;
    }
    
    //set the second line by countries.
    private function setSecondLineWithAvesByCountry($data,$package_id,$countries,$dateby,$date_time_list,$package_keys) {
        $body = '<tr>'.
                '   <td colspan="5">'.
                '       <div align="center">';
        foreach($countries as $key=>$val) {
            foreach($val as $country_code=>$country_name) {
                $body .= '<p><strong>'.ucwords($key).' - '.ucwords($country_name).' ('.$country_code.')</strong></p>';
                $body .= '<p>';
                $body .= $this->setSubscriptionPlanLineChart($country_code,$data,$package_id,$date_time_list,$package_keys);
                $body .= '<table width="100%" border="0">'.self::setPlanTableHeader($dateby).$this->setPlanTableBody($data,$date_time_list,$package_id,$country_code).'</table>'.
                         '</p>';
            }
        }

        $body .= '      </div>'.
                 '  </td>'.
                 '</tr>'.
                 '<tr><td colspan="5">&nbsp;</td></tr>';

        return $body;
    }

    //get the line chart with datas.
    private function setSubscriptionPlanLineChart($aves_list,$data,$package_id,$date_time_list,$package_keys) {
        $tmp_val_data = array();
        $tmp_labels = array();
        $body = null;
        $aves_list_flag = (strtoupper($aves_list)=='NONE') ? true : false;
        $count_new_zero = 0;
        $count_renew_zero = 0;

        if (!in_array($package_id,$package_keys)) return $body;

        foreach($date_time_list as $key=>$value) {
            $tmp_labels[] = (strlen($value)==10) ? substr($value,5,5) : $value;
            $new_num = 0;
            $renew_num = 0;

            if ($aves_list_flag) {
                //gender = none.
                if (isset($data[$value][$package_id])) {
                    foreach($data[$value][$package_id] as $k=>$v) {
                        $new_num += (isset($v['new'])) ? $v['new'] : 0;
                        $renew_num += (isset($v['renew'])) ? $v['renew'] : 0;
                    }
                }
            }
            else {
                //normal.
                $new_num = (isset($data[$value][$package_id][$aves_list]['new'])) ? (int)$data[$value][$package_id][$aves_list]['new'] : 0;
                $renew_num = (isset($data[$value][$package_id][$aves_list]['renew'])) ? (int)$data[$value][$package_id][$aves_list]['renew'] : 0;
            }
            if ($new_num==0) $count_new_zero++;
            if ($renew_num==0) $count_renew_zero++;
            $tmp_val_data['new'][] = $new_num;
            $tmp_val_data['renew'][] = $renew_num;

        }

        if (!empty($tmp_labels)) {
            if (count($tmp_val_data['new'])==$count_new_zero && count($tmp_val_data['renew'])==$count_renew_zero) return $body;
            $data_array = array(
                            array('data'=>$tmp_val_data['new'],'capture'=>'New'),
                            array('data'=>$tmp_val_data['renew'],'capture'=>'Renew'),
                          );
            $labels = json_encode($tmp_labels);
            $data_value = json_encode($data_array);
            $body .= '<input type="hidden" class="canvasCurveLines" value=\''.$data_value.'\' labels=\''.$labels.'\' />'; 
        }

        return $body;
    }

    //set body by gender.
    private function setMainBodyListForSubscriptionPlanByGender($data,$package,$gender,$dateby,$date_time_list) {
        $body_list = null;
        $package_arr = self::getPackageArr();
        if (empty($gender)) $gender = array('NONE');
        $package_keys = array();
        foreach($data as $k=>$v) {
            foreach($v as $k1=>$v1) {
                $package_keys[$k1] = $k1;
            }
        }
        //set body with loop.
        foreach($package as $key=>$value) {
            $body_list .= $this->setSubParagraphTitle($package_arr[$value]);
            $body_list .= $this->setSecondLineWithAvesByGender($data,$value,$gender,$dateby,$date_time_list,$package_keys);
        }
        return $body_list;
    }
    
    //set body by countries.
    private function setMainBodyListForSubscriptionPlanByCountry($data,$package,$countries,$dateby,$date_time_list) {
        $body_list = null;
        $package_arr = self::getPackageArr();
        $package_keys = array();
        foreach($data as $k=>$v) {
            foreach($v as $k1=>$v1) {
                $package_keys[$k1] = $k1;
            }
        }

        //set body with loop
        foreach($package as $key=>$value) {
            $body_list .= $this->setSubParagraphTitle($package_arr[$value]);
            $body_list .= $this->setSecondLineWithAvesByCountry($data,$value,$countries,$dateby,$date_time_list,$package_keys);
        }
        return $body_list;
    }

    
    //get the  count data for Gender or AgeGroup with package ids.
    //get datas - region & countries.
    private function getSubscriptionPlansGroupData($date_condition,$age_group,$gender,$package_ids,$dateby,$countries_code,$group_type) {
        $data = array();
        $country_group_condition = null;
        if (!empty($countries_code)) {
            foreach($countries_code as $key=>$value) {
                $value_ = array_keys($value);
                $country_group_condition .= "'".implode("','",$value_)."',";
            }
            $country_group_condition = ' AND country_code IN ( '.substr($country_group_condition,0,strlen($country_group_condition)-1).' )';
        }
        $age_group_condition = (!empty($age_group)) ? ' AND age_group='.$age_group : null;
        $package_condition = (!empty($package_ids)) ? ' AND package_id IN ('.implode(',',$package_ids).') ' : null;
        $gender_condition = (!empty($gender)) ? ' AND gender IN ("'.implode('","',$gender).'") ' : null;
        $condition = $date_condition.$age_group_condition.$package_condition.$gender_condition.$country_group_condition;
        
        //get instance .
        $obj = new ModelReportPages();
        if ($group_type == AC::SUBSCRIPTION_PLAN_TYPE_OF_COUNTRY) {
            $data = $obj->getRegionAndCountryGroupForPlan($condition,$package_ids,$dateby);
        }
        elseif($group_type == AC::SUBSCRIPTION_PLAN_TYPE_OF_AGE) {
            $data = $obj->getGenderAndAgeGroupForPlan($condition,$package_ids,$dateby);
        }

        return $data;
    }

    private function setBlankLineWithMessage($message=null) {
        $message = (!empty($message)) ? $message : ErrorMessage::HAVE_NO_DATA;
        $body ='<tr height="60"><td align="center">'.$message.'</td></tr>';
        return $body;
    }

    //set the Gender&Age Group Body string.
    private function setGenderAndAgeGroupBodyString($conditions) {
        if (empty($conditions)) return ErrorMessage::HAVE_NO_PARAMERTERS;
        $condition = array();
        $data = array();
        $gender_age_body = null;
        $age_group_array = array();
        $condition = $conditions['condition'];
        $tmp_date_arr = $this->getDateCondition($condition['play_time']);
        $date_condition = $tmp_date_arr['condition'];
        $datetime_list = $tmp_date_arr['time_list'];
        
        //init.
        $age_group_array = self::getAgeGroupArr();
        $is_age_all_flag = (count($age_group_array)==count($condition['age_group'])) ? true : false;
        $age_group_id = ($is_age_all_flag || empty($condition['age_group'])) ? false : $condition['age_group'][0];
        $package_arr = self::getPackageArr();
        $package_ids = (count($condition['package'])==count($package_arr)) ? false : $condition['package'];
        //countries.
        $countries_code = AC::getInstance()->getCountryCodesListByRegion($condition['country_code']);

        //get datas.
        $data = $this->getSubscriptionPlansGroupData($date_condition,$age_group_id,$condition['gender'],$package_ids,$condition['dateby'],$countries_code,AC::SUBSCRIPTION_PLAN_TYPE_OF_AGE);

        //set bodys.
        $sub_title = ($is_age_all_flag) ? ((!empty($condition['gender'])) ? AC::VIDEO_VIEWING_REPORT_GENDER_AGE_GROUP : null) : ((!empty($condition['gender'])) ? AC::VIDEO_VIEWING_REPORT_GENDER_GROUP : AC::VIDEO_VIEWING_REPORT_TOTAL_SUMMARY);

        $gender_age_body =  $this->setParagraphTitle($sub_title);
        $gender_age_body .= (!empty($data)) ? $this->setMainBodyListForSubscriptionPlanByGender($data,$condition['package'],$condition['gender'],$condition['dateby'],$datetime_list) : $this->setBlankLineWithMessage();

        return $gender_age_body;
    }
    
    //set the Region&Country Group Body string.
    private function setRegionCountryGroupBodyString($conditions) {
        if (empty($conditions)) return ErrorMessage::HAVE_NO_PARAMETERS;
        $condition = array();
        $region_country_body = null;
        $age_group_array = array();
        $condition = $conditions['condition'];
        $tmp_date_arr = $this->getDateCondition($condition['play_time']);
        $date_condition = $tmp_date_arr['condition'];
        $datetime_list = $tmp_date_arr['time_list'];

        $countries_code = AC::getInstance()->getCountryCodesListByRegion($condition['country_code']);

        if (!empty($condition['country_code'])) {
            //init
            $age_group_array = self::getAgeGroupArr();
            $is_age_all_flag = (count($age_group_array)==count($condition['age_group'])) ? true : false;
            $age_group_id = ($is_age_all_flag || empty($condition['age_group'])) ? false : $condition['age_group'][0];
            $package_arr = self::getPackageArr();
            $package_ids = (count($condition['package'])==count($package_arr)) ? false : $condition['package'];
            //get datas.
            $data = $this->getSubscriptionPlansGroupData($date_condition,$age_group_id,$condition['gender'],$package_ids,$condition['dateby'],$countries_code,AC::SUBSCRIPTION_PLAN_TYPE_OF_COUNTRY);
            //set bodys.
            $region_country_body .= $this->setParagraphTitle(AC::VIDEO_VIEWING_REPORT_REGION_COUNTRY_GROUP);
            $region_country_body .= (!empty($data)) ? $this->setMainBodyListForSubscriptionPlanByCountry($data,$condition['package'],$countries_code,$condition['dateby'],$datetime_list) : $this->setBlankLineWithMessage();
        }
        else {
            $region_country_body .= $this->setParagraphTitle(AC::VIDEO_VIEWING_REPORT_REGION_COUNTRY_GROUP);
            $region_country_body .= $this->setBlankLineWithMessage();
        }

        return $region_country_body;
    }

    //entrance
    protected function __renderHead() {
        $body_string = null;
        $rand_code = rand(10000,99999);

        //parameters re-assignment.
        $conditions = $_GET;
        $conditions['country_code'] = $conditions['country'];
        $conditions = $this->getPageCondition($conditions);

        //get the header string.
        $head_string = $this->setHeadString($conditions['condition'],null,$rand_code);

        //gender & age group
        $body_string .= $this->setGenderAndAgeGroupBodyString($conditions);

        //region & country group
        $body_string .= $this->setRegionCountryGroupBodyString($conditions);

        //write a tmp file Export Tool.
        $export_html_string = $this->getOutPutBody($head_string['export'],$body_string);
        $write_result = AC::getInstance()->writeTempBodyToFile($rand_code,$export_html_string);
        
        //output.
        $this->contents =$this->getOutPutBody($head_string['view'],$body_string); 

    }

}
?>